package org.zhb.querysql.model;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.List;

/**
 * The persistent class for the s_function database table.
 * 
 */
@Entity
@Table(name = "s_function")
@DynamicUpdate(true)
public class Function implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@Column(unique = true, nullable = false, length = 32)
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(strategy = "uuid", name = "uuid")
	private String id;

	@Column(length = 200)
	private String description;

	@NotNull(message = "权限代码不能为空!")
	@Column(name = "function_code", length = 40)
	private String functionCode;

	@NotNull(message = "权限名称不能为空!")
	@Column(name = "function_name", length = 40)
	private String functionName;

	@Column(name = "generate_munu", length = 100)
	private String generateMunu;

	@Column(length = 100)
	private String page;

	private int zindx;

	// bi-directional many-to-one association to Function
	@ManyToOne
	@JoinColumn(name = "parent_id")
	private Function Function;

	// bi-directional many-to-one association to Function
	@OneToMany(mappedBy = "Function")
	private List<Function> Functions;

	// bi-directional many-to-one association to RoleFunction
	@OneToMany(mappedBy = "Function")
	private List<RoleFunction> RoleFunctions;

	public Function() {
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getFunctionCode() {
		return this.functionCode;
	}

	public void setFunctionCode(String functionCode) {
		this.functionCode = functionCode;
	}

	public String getFunctionName() {
		return this.functionName;
	}

	public void setFunctionName(String functionName) {
		this.functionName = functionName;
	}

	public String getGenerateMunu() {
		return this.generateMunu;
	}

	public void setGenerateMunu(String generateMunu) {
		this.generateMunu = generateMunu;
	}

	public String getPage() {
		return this.page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public int getZindx() {
		return this.zindx;
	}

	public void setZindx(int zindx) {
		this.zindx = zindx;
	}

	public Function getFunction() {
		return this.Function;
	}

	public void setFunction(Function Function) {
		this.Function = Function;
	}

	public List<Function> getFunctions() {
		return this.Functions;
	}

	public void setFunctions(List<Function> Functions) {
		this.Functions = Functions;
	}

	public Function addFunction(Function Function) {
		getFunctions().add(Function);
		Function.setFunction(this);

		return Function;
	}

	public Function removeFunction(Function Function) {
		getFunctions().remove(Function);
		Function.setFunction(null);

		return Function;
	}

	@JsonIgnore
	public List<RoleFunction> getRoleFunctions() {
		return this.RoleFunctions;
	}

	public void setRoleFunctions(List<RoleFunction> RoleFunctions) {
		this.RoleFunctions = RoleFunctions;
	}

	public RoleFunction addRoleFunction(RoleFunction RoleFunction) {
		getRoleFunctions().add(RoleFunction);
		RoleFunction.setFunction(this);

		return RoleFunction;
	}

	public RoleFunction removeRoleFunction(RoleFunction RoleFunction) {
		getRoleFunctions().remove(RoleFunction);
		RoleFunction.setFunction(null);

		return RoleFunction;
	}

}